package encome.work.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import encome.work.dao.Supplier;
import encome.work.mapper.SupplierMapper;
import encome.work.service.SupplierService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author fyftless
 */

@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {

    @Resource
    private SupplierMapper supplierMapper;

    @Override
    public void add(Supplier supplier) {
        supplierMapper.insert(supplier);
    }

    @Override
    public void update(Supplier supplier) {
        supplierMapper.updateById(supplier);
    }

    @Override
    public void delete(Long id) {
        supplierMapper.deleteById(id);
    }

    @Override
    public Page<Supplier> findPage(Supplier supplier, Integer page, Integer pageSize) {
        Page<Supplier> pageInfo = new Page<>(page, pageSize);
        LambdaQueryWrapper<Supplier> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(supplier.getContent()),
                Supplier::getContent, supplier.getContent());
        return supplierMapper.selectPage(pageInfo, queryWrapper);
    }

    @Override
    public Supplier findById(Long id) {
        return supplierMapper.selectById(id);
    }

    @Override
    public Page<Supplier> findPage(Integer page, Integer pageSize) {
        Page<Supplier> pageInfo = new Page<>(page, pageSize);
        LambdaQueryWrapper<Supplier> queryWrapper = new LambdaQueryWrapper<>();
        return supplierMapper.selectPage(pageInfo, queryWrapper);
    }
}
